// @algorithm @lc id=2145 lang=cpp 
// @title grid-game


#define print(...)
class Solution {
public:
    long long gridGame(vector<vector<int>>& grid) {
        int m = 2, n = grid[0].size();
        vector<long long> post(n, 0), pre(n, 0);
        for(int j=n-1; j>0; j--) //line1: sum right to left
            post[j-1] = post[j] + grid[0][j]; // [0, n-2]
        for(int j=0; j<n-1; j++) //line2: sum left to right
            pre[j+1] = pre[j] + grid[1][j];   // [1, n-1]
        print("post:", post, "\n")
        print("pre:", pre, "\n")
        long long mini = max(post[0], pre[0]);
        for(int j=1; j<n; j++)
            mini = min(mini, max(post[j], pre[j]));
        return mini;
    }
};